<?php

class Database {
    private $hostname;
    private $port;
    private $user;
    private $password;
    private $name;

    private $connection;

    public function __construct($name) {
        $this->connection=null;
        $this->hostname="localhost";
        $this->port=3306;
        $this->user="";
        $this->password="";
        $this->name=$name;
    }

    public function getConnection(){
        if ($this->connection==null){
           $this->connection = mysql_connect($this->hostname.":".$this->port, $this->user, $this->password) or die("Connection to database failed: " . mysql_error());
           mysql_select_db($this->name) or die("Unable to find database: " . mysql_error());
        }
        return $this->connection;
    }

    public function closeConnection(){
        mysql_close($this->connection);
    }

    public function getHostname(){
        return $this->hostname;
    }
    public function getPort(){
        return $this->port;
    }
    public function getUser(){
        return $this->user;
    }
    public function getPassword(){
        return $this->password;
    }
    public function getName(){
        return $this->name;
    }

    public function setHostname($hostname){
        $this->hostname=$hostname;
    }
    public function setPort($port){
        $this->port=$port;
    }
    public function setUser($user){
        $this->user=$user;
    }
    public function setPassword($password){
        $this->password=$password;
    }
    public function setName($name){
        $this->name=$name;
    }
}
?>
